<template>
  <div class="nav-header">
    <el-icon :size="25" class="fold-menu" @click="clickFold">
      <component :is="foldIcon"></component>
    </el-icon>
    <div class="content">
      <div><cc-breadcrumb :data="breadcrumb"></cc-breadcrumb></div>
      <div><user-info></user-info></div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, computed } from 'vue'
import UserInfo from './user-info.vue'
import { CcBreadcrumb } from '@/base-ui/breadcrumb'
import { getBreadcrumb } from '@/utils/map-menus'
import { useStore } from '@/store'
import { useRoute } from 'vue-router'

export default defineComponent({
  components: { UserInfo, CcBreadcrumb },
  emits: ['foldChange'],
  setup(props, { emit }) {
    let isFold = true
    let foldIcon = ref('expand')
    const clickFold = () => {
      isFold = !isFold
      if (isFold) foldIcon.value = 'expand'
      else foldIcon.value = 'fold'
      emit('foldChange', isFold)
    }

    const store = useStore()

    const breadcrumb = computed(() => {
      const userMenus = store.state.login.userMenu
      const path = useRoute().path
      return getBreadcrumb(userMenus, path)
    })
    return { clickFold, foldIcon, breadcrumb }
  }
})
</script>
<style scoped lang="less">
.nav-header {
  display: flex;
  width: 100%;

  .fold-menu {
    cursor: pointer;
  }

  .content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    padding: 0 20px;
  }
}
</style>
